import 'package:flutter/material.dart';
import 'package:xingsu/page/user/viewmodel/login_viewmodel.dart';
import 'package:xingsu/res/colors.dart';
import 'package:xingsu/util/image_util.dart';
import 'package:get/get.dart';
import 'package:xingsu/util/widget_util.dart';

class LoginPage extends StatelessWidget {
  final LoginViewModel _viewModel = LoginViewModel();

  @override
  Widget build(BuildContext context) {
    final email = TextFormField(
      keyboardType: TextInputType.emailAddress,
      autofocus: false,
      controller: _viewModel.phoneController,
      decoration: InputDecoration(
          hintText: '请输入手机号',
          contentPadding: const EdgeInsets.fromLTRB(10.0, 2.0, 10.0, 10.0),
          enabledBorder: UnderlineInputBorder(
              borderSide:
                  BorderSide(color: Get.theme.dividerTheme.color!, width: 0.5)),
          focusedBorder: const UnderlineInputBorder(
              borderSide: BorderSide(color: Color(0xFF6AF7D8)))),
    );

    final password = TextFormField(
      autofocus: false,
      obscureText: true,
      controller: _viewModel.pwdController,
      decoration: InputDecoration(
          hintText: '请输入密码',
          contentPadding: const EdgeInsets.fromLTRB(10.0, 2.0, 10.0, 10.0),
          enabledBorder: UnderlineInputBorder(
              borderSide:
                  BorderSide(color: Get.theme.dividerTheme.color!, width: 0.5)),
          focusedBorder: const UnderlineInputBorder(
              borderSide: BorderSide(color: Color(0xFF6AF7D8)))),
    );

    final regButton = InkWell(
      onTap: _viewModel.registerClick,
      child: const Padding(
        padding: EdgeInsets.symmetric(vertical: 16.0),
        child: Text(
          '用户注册',
          style: TextStyle(color: Colors.grey),
        ),
      ),
    );

    final forgetButton = InkWell(
      onTap: _viewModel.forgetClick,
      child: const Padding(
        padding: EdgeInsets.symmetric(vertical: 16.0),
        child: Text(
          '忘记密码',
          style: TextStyle(color: Colors.grey),
        ),
      ),
    );

    final loginButton =
        WidgetUtil.btnWidget(title: "登录", clickCallback: _viewModel.loginClick);

    return Scaffold(
        appBar: AppBar(
          title: const Text(
            '登录',
          ),
        ),
        body: ListView(
          padding: const EdgeInsets.only(left: 24.0, right: 24.0, top: 20.0),
          children: <Widget>[
            loadAssetImage("logo", width: 100, height: 100),
            const SizedBox(height: 48.0),
            email,
            const SizedBox(height: 28.0),
            password,
            const SizedBox(height: 24.0),
            loginButton,
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [regButton, forgetButton],
            )
          ],
        ));
  }
}
